#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         Tody Kwok
 Date:			2019-04-10
 Script Function:
	this script is for ME Keyboard backlight testing.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#pragma compile(x64, true)
#pragma compile(FileVersion, 1.0.0.0)
#pragma compile(ProductVersion, 1.0.0.0)
#pragma compile(ProductName, "KBL_Factory.exe")
#pragma compile(LegalCopyright, '(c) Tody, 2019 T-ware Inc.')
#pragma compile(FileDescription, ME Keyboard backlight testing tool)
#pragma compile(Icon, C:\Program Files (x86)\AutoIt3\Icons\MyAutoIt3_Green.ico)

#RequireAdmin
#NoTrayIcon

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $batFile=@ScriptDir&"\kbl_test.bat"
Global $binFile=@ScriptDir&"\Kbbl.exe"

main()

Func WriteBatch($id)
	If FileExists($batFile) Then FileDelete($batFile)
	FileWriteLine($batFile, $binFile&" -C RED -B 4 -L " &$id& " & pause")
	FileWriteLine($batFile, $binFile&" -C ORANGE -B 4 -L " &$id& " & pause")
	if $id=0 Or $id=1 Then FileWriteLine($batFile, $binFile&" -C ORANGE_LIGHTER -B 4 -L " &$id& " & pause")
	If $id=2 Then FileWriteLine($batFile, $binFile&" -C YELLOW -B 4 -L " &$id& " & pause")
	FileWriteLine($batFile, $binFile&" -C GREEN -B 4 -L " &$id& " & pause")
	FileWriteLine($batFile, $binFile&" -C BLUE -B 4 -L " &$id& " & pause")
	FileWriteLine($batFile, $binFile&" -C INDIGO -B 4 -L " &$id& " & pause")
	FileWriteLine($batFile, $binFile&" -C PURPLE -B 4 -L " &$id& " & pause")
	If $id=2 then FileWriteLine($batFile, $binFile&" -C WHITE -B 4 -L " &$id& " & pause")
EndFunc

Func main()
	If not FileExists($binFile) Then
		MsgBox(48, "Error", "kbbl.exe is missing")
		Exit 1
	EndIf
	GUICreate("键盘背光测试1.0", 260,120) ; will create a dialog box that when displayed is centered
	If FileExists($batFile) Then FileDelete($batFile)
	Local $idEverlight = GUICtrlCreateRadio("亿光", 10, 10, 120, 20)
	Local $idLiteOn = GUICtrlCreateRadio("光宝", 10, 40, 120, 20)
	Local $idfenBIN = GUICtrlCreateRadio("白光分BIN", 10, 70, 120, 20)
	Local $idStart = GUICtrlCreateButton("开始测试", 160, 10, 85, 85)
	;;GUICtrlSetState($idEverlight, $GUI_CHECKED)

	If not FileExists($batFile) Then GUICtrlSetState($idStart, $GUI_DISABLE)

	GUISetState(@SW_SHOW) ; will display an  dialog box

	Local $idMsg
	; Loop until the user exits.
	While 1
		$idMsg = GUIGetMsg()
		Select
		Case $idMsg = $GUI_EVENT_CLOSE
			If FileExists($batFile) Then FileDelete($batFile)
				ExitLoop
			Case $idMsg = $idEverlight And BitAND(GUICtrlRead($idEverlight), $GUI_CHECKED) = $GUI_CHECKED
				GUICtrlSetState($idStart, $GUI_DISABLE)
				WriteBatch(1)
				GUICtrlSetState($idStart, $GUI_ENABLE)
			Case $idMsg = $idLiteOn And BitAND(GUICtrlRead($idLiteOn), $GUI_CHECKED) = $GUI_CHECKED
				GUICtrlSetState($idStart, $GUI_DISABLE)
				WriteBatch(0)
				GUICtrlSetState($idStart, $GUI_ENABLE)
			Case $idMsg = $idfenBIN And BitAND(GUICtrlRead($idfenBIN), $GUI_CHECKED) = $GUI_CHECKED
				GUICtrlSetState($idStart, $GUI_DISABLE)
				WriteBatch(2)
				GUICtrlSetState($idStart, $GUI_ENABLE)
			Case $idMsg = $idStart
			RunWait($batFile)
		EndSelect
	WEnd
EndFunc   ;==>end main
